package sis.threadtest;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-08-01 19:57
 * @notify
 * @version 1.0
 */

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyService {
    private Lock lock = new ReentrantLock();

    public void serviceA() {
        lock.lock();//serviceA ,serviceB 中的lock是同一把锁哦，谁先获取谁就有控制权。
        for (int i = 0; i < 3; i++) {
            try {
                wait();
            } catch (Exception E) {
            }
            System.out.println(Thread.currentThread().getName() + "----Ai=" + i);
        }
        lock.unlock();
    }

    public void serviceB() {
        lock.lock();
        for (int i = 0; i < 3; i++) {
            System.out.println(Thread.currentThread().getName() + "----Bi=" + i);
        }
        notify();
        lock.unlock();
    }

}
